package com.qf.contorller;

import com.netflix.discovery.EurekaClient;
import com.qf.pojo.User;
import com.qf.searchFeign.Feign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author jiangjingbo
 * @version V1.0
 * @Project java2203
 * @Package com.qf.contorller
 * @Description:
 * @Date 2022/7/6 11:44
 */
@RestController
@RequestMapping("/test")
public class CustomerContorller {

    @Autowired
    private EurekaClient eurekaClient;

    @Autowired
        //底层使用http协议
    private RestTemplate restTemplate;
    @Autowired
    private Feign feign;
    @RequestMapping("/consumer")
    public String countm(){

        //1. 通过eurekaClient对象获取search搜索微服务的对象信息
//        InstanceInfo info = eurekaClient.getNextServerFromEureka("QF-SEARCH",false);
        //2. 从搜索微服务对象信息中获取搜索微服务的ip和端口号
//        String pageUrl = info.getHomePageUrl();
//        System.out.println("====pageUrl======="+pageUrl);

        //3. 通过restTemplate对象发送http协议远程调用
        String forObject = restTemplate.getForObject("http://QF-SEARCH/search/test", String.class);
        //4. 返回结果
        System.out.println(forObject);
        return forObject;
    }

    @RequestMapping("/test1")
    public  String test(){
        String test = feign.test();
        System.out.println("=========test"+test);
        return test;
    }

        @RequestMapping("/findid")
    public User test2(){
        User byId = feign.findById(1);
        System.out.println(byId);
        return byId;
    }
    @RequestMapping("/qqq")
    public  User user(){
        User user = feign.test1(1);
        return user;
    }

    @RequestMapping("/www")
    public String testrr(){
        String s = feign.Test2();
        return s;
    }

}
